<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<head>
		<title>设置客户网点</title>
		<script>
		 var groupCode="";
		 function setGroupcode(item){
			 alert(item);
			 groupCode=item;
		 }
		 
		  
		  function myCheckedAll() {
				var tempChecked = "";
				$("input[type='checkbox'][name='leveGroupCode']:checked").each(function() {
					var value = $(this).val();
					var textValue=$("#leve_"+value).val();
					if (tempChecked == "") {
						tempChecked=value+":"+textValue;
					} else {
						tempChecked = tempChecked + "," + value+":"+textValue;
					}
				});
				return tempChecked;
			}
		  
		  function ajaxSetGroupCodes() {
			  var params=myCheckedAll();
				$.ajax({
					type : 'post',
					url : '${ctx}/v2/customerAreaGroup/ajaxSetGroupCodes',
					data :  {
						customerCode:'${customers.customerCode}',
						groupCode:groupCode,
						params:params
					},
					dataType : 'json',
					success : function(data) {
						$("#message").show();
						$("#message").html(data.content);
					},
					error : function() {
						alert("获取信息错误");
					}
				});
			}
		  
		 
		  
		  function ajaxCustomerAreaGroup(item) {
			  groupCode=item;
				$.ajax({
					type : 'post',
					url : '${ctx}/v2/customerAreaGroup/ajaxCustomerAreaGroup',
					data : 'customerCode=${customers.customerCode}&groupCode='+item,
					dataType : 'json',
					success : function(data) {
						if(data.status=="1"){
							var tempString="";
							$.each(data.content.leveDTOs,function(i,obj){
								tempString+="<tr>";
								
								tempString+="<td>";
								tempString+=obj.groupName;
								tempString+="</td>";
								
								tempString+="<td>";
								tempString+="<input type=\"text\" id=\"leve_"+obj.groupCode+"\" value=\""+obj.leve+"\"/>";
								tempString+="</td>";
								
								tempString+="<td>";
								if(obj.leve==null||""==obj.leve){
									tempString+="<input type=\"checkbox\" name=\"leveGroupCode\" value=\""+obj.groupCode+"\" >";
								}else{
									tempString+="<input type=\"checkbox\" name=\"leveGroupCode\" value=\""+obj.groupCode+"\" checked>";
								}
								
								tempString+="</td>";
								
							    tempString+="</tr>";
							});
							$("#tbodyContent").html(tempString);
						}else{
							$("#message").html(data.content);
						}
						$("#message").show();
					},
					error : function() {
						alert("获取信息错误");
					}
				});
			}
		  
		
		</script>
	</head>

	<body>
	<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">${object.customerName } 网点信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">	
	    <div id="message" class="alert alert-success" style="display: none;">
		</div>
	
		<table class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>
						网点名称
					</th>
					<th>
						网点介绍
					</th>
					<th>
						优先级
					</th>
					<th style="width: 150px">
					         流转网点
					</th>
					<th>
						覆盖的省份
					</th>
					
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${object.webAreaGroupDtos}" var="obj">
					<tr>
						<td>
							${obj.groupName }
						</td>
						<td>
							${obj.groupIntro }
						</td>
						<td>
							${obj.level }
						</td>
						<td>
							<c:forEach items="${ fn:split(obj.nextGroupCode, ',') }" var="nextGroupCode">
								<c:forEach items="${ fn:split(nextGroupCode, ':') }" var="groupCode" varStatus="i">
									 <c:if test="${i.index == 0}">
									 	<c:forEach items="${object.webAreaGroupDtos}" var="obj2">
									 		 <c:if test="${obj2.groupCode == groupCode}">
									 		 	${obj2.groupName }:
									 		 </c:if>
									 	</c:forEach>
									 </c:if>
									 <c:if test="${i.index == 1}">
									 		${groupCode }<br/>
									 </c:if>
								</c:forEach>
							</c:forEach>
						</td>
						<td id='obj${obj.id }'>
							${obj.areas }
						</td>
						<%-- <td>
				          <a href="#areaGroups" onclick="ajaxCustomerAreaGroup('${obj.groupCode}');"   role="button" class="btn btn-small" data-toggle="modal">设置订单流转网点</a>
						  
						</td> --%>
					</tr>
				</c:forEach>
			</tbody>
		</table>
		
		<div id="areaGroups"  class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" role="dialog">
			<div class="modal-header">
				<h4 id="consignorTitle">请选择网点</h4>
			</div>
			<div id="consignorDetailBodyOut" class="modal-body">
				<table id="consignorDetailBody" class="table table-striped table-bordered table-condensed">
				  <thead>
				    <tr>
				      <td>网点名称</td>
				      <td>优先级</td>
				      <td>操作</td>
				    </tr>
				  </thead>
				  <tbody id="tbodyContent">
				    <c:forEach items="${ags}" var="obj">
					 <tr>
						<td>
							${obj.groupName }
						</td>
						<td>
							<input type="text" id="leve_${obj.groupCode }"/>
						</td>
						<td>
							<input type="checkbox" name="leveGroupCode" value="${obj.groupCode }"   style="width: 1%;">
						</td>
					</tr>
					</c:forEach>
				  </tbody>
				</table>
			</div>
			<div class="modal-footer bg-gray">
				<button class="btn" data-dismiss="modal" aria-hidden="true" onclick="ajaxSetGroupCodes();">确定</button>
				<button class="btn" data-dismiss="modal" aria-hidden="true">返回</button>
			</div>
		</div>		
			</div>
		</div>	
		</div>
		</div>
		</section>	
	</body>
</html>
